import 'package:aidw_ui/app_theme.dart';
import 'package:aidw_ui/string_res/str_res_keys.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../widget/custiom_edit_field.dart';
import 'logic.dart';

class LoginPage extends StatelessWidget {
  final logic = Get.find<LoginLogic>();
  final state = Get.find<LoginLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          // 标题
          SizedBox(
            height: 64.h,
          ),
          Text(
            '登录',
            style: AppTheme.appTheme.headline1(fontWeight: FontWeight.bold, fontSize: 100.sp),
          ),
          SizedBox(
            height: 48.h,
          ),
          ScaleTransition(
            scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
              parent: logic.animationController,
              curve: Interval(0, 0.3, curve: Curves.fastOutSlowIn),
            )),
            child: CustomEditField(
              maxLength: 11,
              autoFucus: false,
              inputType: TextInputType.phone,
              initValue: '',
              hintText: '手机号',
              hintTextStyle: AppTheme.appTheme
                  .hint(fontWeight: FontWeight.normal, fontSize: 16),
              textStyle: AppTheme.appTheme
                  .headline1(fontWeight: FontWeight.normal, fontSize: 16),
              containerDecoration: BoxDecoration(
                  shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  color: AppTheme.appTheme.containerBackgroundColor()),
              numDecoration: BoxDecoration(
                  shape: BoxShape.rectangle,
                  color: AppTheme.appTheme.cardBackgroundColor(),
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  boxShadow: AppTheme.appTheme.containerBoxShadow()),
              numTextStyle: AppTheme.appTheme
                  .themeText(fontWeight: FontWeight.bold, fontSize: 15),
              onValueChanged: (value) {
                // setState(() {
                   state.phone = value;
                // });
              },
            ),
          ),
          SizedBox(
            height: 16,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ScaleTransition(
                scale:
                Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
                  parent: logic.animationController,
                  curve: Interval(0.3, 0.6, curve: Curves.fastOutSlowIn),
                )),
                child: Container(
                  width: 250,
                  child: CustomEditField(
                    maxLength: 6,
                    autoFucus: false,
                    inputType: TextInputType.phone,
                    initValue: '',
                    hintText: '验证码',
                    hintTextStyle: AppTheme.appTheme
                        .hint(fontWeight: FontWeight.normal, fontSize: 16),
                    textStyle: AppTheme.appTheme.headline1(
                        fontWeight: FontWeight.normal, fontSize: 16),
                    containerDecoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.all(Radius.circular(15)),
                        color: AppTheme.appTheme.containerBackgroundColor()),
                    numDecoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        color: AppTheme.appTheme.cardBackgroundColor(),
                        borderRadius: BorderRadius.all(Radius.circular(15)),
                        boxShadow: AppTheme.appTheme.containerBoxShadow()),
                    numTextStyle: AppTheme.appTheme
                        .themeText(fontWeight: FontWeight.bold, fontSize: 15),
                    onValueChanged: (value) {
                      // setState(() {
                      state.code = value;
                      // });
                    },
                  ),
                ),
              ),
              SlideTransition(
                position: Tween<Offset>(begin: Offset(2, 0), end: Offset.zero)
                    .animate(CurvedAnimation(
                    parent: logic.animationController,
                    curve:
                    Interval(0.6, 0.8, curve: Curves.fastOutSlowIn))),
                child: GestureDetector(
                  onTap: () {
                    if (!logic.hasPhone()) {
                      return;
                    }
                    Get.snackbar("提示", "发送成功！");
                  },
                  onDoubleTap: () {},
                  child: Container(
                    alignment: Alignment.center,
                    height: 50,
                    width: 70,
                    decoration: BoxDecoration(
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.all(
                          Radius.circular(10),
                        ),
                        color: logic.hasPhone()
                            ? AppTheme.appTheme.grandientColorEnd()
                            : AppTheme.appTheme
                            .grandientColorEnd()
                            .withOpacity(0.5)),
                    child: Text(
                      '60',
                      style: AppTheme.appTheme.headline1(
                          fontSize: 16,
                          fontWeight: FontWeight.normal,
                          textColor: Colors.white),
                    ),
                  ),
                ),
              )
            ],
          ),
          SizedBox(
            height: 32,
          ),
          ScaleTransition(
            scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
              parent: logic.animationController,
              curve: Interval(0.8, 1, curve: Curves.fastOutSlowIn),
            )),
            child: GestureDetector(
              onTap: () {
                // FlashHelper.toast(context, '登录成功');
                // User user = User(Uuid().generateV4(), '', phone);
                // SessionUtils.sharedInstance().login(user);
                // Navigator.of(context).pop();
              },
              onDoubleTap: () {},
              child: Container(
                alignment: Alignment.center,
                height: 55,
                width: 220,
                decoration: BoxDecoration(
                    boxShadow: AppTheme.appTheme.coloredBoxShadow(),
                    gradient: logic.hasPhoneAndCode()
                        ? AppTheme.appTheme.containerGradient()
                        : AppTheme.appTheme
                        .containerGradientWithOpacity(opacity: 0.5),
                    borderRadius: BorderRadius.all(Radius.circular(35))),
                child: Text(
                  'Login',
                  style: AppTheme.appTheme.headline1(
                      textColor: Colors.white,
                      fontSize: 18,
                      fontWeight: FontWeight.w600),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
